package p270jp.pxv.android.viewholder;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.bumptech.glide.load.engine.GlideException;
import java.util.List;
import p047bg.C1124a;
import p140eo.C2973b;
import p165fo.C3114c;
import p172g5.DataSource;
import p216hn.DefaultConstructorMarker;
import p270jp.pxv.android.R;
import p270jp.pxv.android.activity.FullScreenImageActivity;
import p270jp.pxv.android.event.ShowWorkMenuOnLongClickEvent;
import p270jp.pxv.android.legacy.model.PixivIllust;
import p270jp.pxv.android.legacy.model.PixivMetaPage;
import p270jp.pxv.android.viewholder.CalcHeightViewHolder;
import p270jp.pxv.android.viewholder.DetailImageViewHolder;
import p307l9.EdgeTreatment;
import p325m0.MutabilityOwnership;
import p368ng.AbstractC5190t2;
import p638y5.RequestListener;
import p664z5.Target;
import p677zi.PixivImageLoader;

/* compiled from: DetailImageViewHolder.kt */
/* renamed from: jp.pxv.android.viewholder.DetailImageViewHolder */
/* loaded from: classes2.dex */
public final class DetailImageViewHolder extends CalcHeightViewHolder {
    private static final float MAX_HEIGHT_SCALE;
    private static final float MIN_HEIGHT_SCALE;
    private final ImageView imageView;
    private final int parentViewWidth;
    private final PixivImageLoader pixivImageLoader;
    public static final Companion Companion = new Companion(null);
    public static final int $stable = 8;

    /* compiled from: DetailImageViewHolder.kt */
    /* renamed from: jp.pxv.android.viewholder.DetailImageViewHolder$Companion */
    /* loaded from: classes2.dex */
    public static final class Companion {
        private Companion() {
        }

        public /* synthetic */ Companion(DefaultConstructorMarker eVar) {
            this();
        }

        public static /* synthetic */ void getLayoutRes$annotations() {
        }

        public final int getLayoutRes() {
            return R.layout.list_item_illust_page;
        }
    }

    /* compiled from: DetailImageViewHolder.kt */
    /* renamed from: jp.pxv.android.viewholder.DetailImageViewHolder$ImageItem */
    /* loaded from: classes2.dex */
    public static final class ImageItem extends CalcHeightViewHolder.CalcHeightItem {
        public static final int $stable;
        private final PixivIllust illust;
        private final int page;

        public ImageItem(PixivIllust pixivIllust, int i) {
            MutabilityOwnership.m3745m(pixivIllust, "illust");
            this.illust = pixivIllust;
            this.page = i;
        }

        public final PixivIllust getIllust() {
            return this.illust;
        }

        public final int getPage() {
            return this.page;
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public DetailImageViewHolder(View view) {
        super(view);
        MutabilityOwnership.m3745m(view, "itemView");
        View findViewById = view.findViewById(R.id.image_view);
        MutabilityOwnership.m3746l(findViewById, "itemView.findViewById(R.id.image_view)");
        this.imageView = (ImageView) findViewById;
        Context context = view.getContext();
        MutabilityOwnership.m3746l(context, "itemView.context");
        this.parentViewWidth = C1124a.m10174r(context);
        Context context2 = view.getContext();
        MutabilityOwnership.m3746l(context2, "itemView.context");
        this.pixivImageLoader = ((AbstractC5190t2) C2973b.m6512b(context2, AbstractC5190t2.class)).mo3376k();
    }

    /* renamed from: bind$lambda-0 */
    public static final void m12305bind$lambda0(PixivIllust pixivIllust, DetailImageViewHolder detailImageViewHolder, int i, View view) {
        MutabilityOwnership.m3745m(pixivIllust, "$illust");
        MutabilityOwnership.m3745m(detailImageViewHolder, "this$0");
        List<PixivMetaPage> list = pixivIllust.metaPages;
        MutabilityOwnership.m3746l(list, "illust.metaPages");
        boolean z = true;
        if ((list.isEmpty() ^ true) || pixivIllust.metaSinglePage.getOriginalImageUrl() != null) {
            Context context = detailImageViewHolder.imageView.getContext();
            MutabilityOwnership.m3746l(context, "imageView.context");
            if (i < 0) {
                z = false;
            }
            EdgeTreatment.m3910h(z);
            Intent intent = new Intent(context, FullScreenImageActivity.class);
            intent.putExtra("KEY_ILLUST", pixivIllust);
            intent.putExtra("KEY_POSITION", i);
            detailImageViewHolder.itemView.getContext().startActivity(intent);
        }
    }

    /* renamed from: bind$lambda-1 */
    public static final boolean m12306bind$lambda1(PixivIllust pixivIllust, int i, View view) {
        MutabilityOwnership.m3745m(pixivIllust, "$illust");
        C3114c.m6284b().m6280f(new ShowWorkMenuOnLongClickEvent(pixivIllust, i, false, 4, null));
        return true;
    }

    private final void bindMultipleImage(ImageItem imageItem) {
        PixivIllust illust = imageItem.getIllust();
        int page = imageItem.getPage();
        int height = imageItem.getHeight();
        if (height == -1) {
            Context context = this.itemView.getContext();
            MutabilityOwnership.m3746l(context, "itemView.context");
            height = C1124a.m10184h(context, 240);
        }
        this.imageView.setLayoutParams(new FrameLayout.LayoutParams(-1, height));
        PixivImageLoader aVar = this.pixivImageLoader;
        Context context2 = this.itemView.getContext();
        MutabilityOwnership.m3746l(context2, "itemView.context");
        aVar.m55k(context2, illust.metaPages.get(page).getImageUrls().getLarge(), this.imageView, new RequestListener<Drawable>(imageItem) { // from class: jp.pxv.android.viewholder.DetailImageViewHolder$bindMultipleImage$1
            public final /* synthetic */ DetailImageViewHolder.ImageItem $imageItem;

            {
                this.$imageItem = r2;
            }

            @Override // p638y5.RequestListener
            public boolean onLoadFailed(GlideException glideException, Object obj, Target<Drawable> iVar, boolean z) {
                MutabilityOwnership.m3745m(obj, "model");
                MutabilityOwnership.m3745m(iVar, "target");
                return false;
            }

            public boolean onResourceReady(Drawable drawable, Object obj, Target<Drawable> iVar, DataSource aVar2, boolean z) {
                MutabilityOwnership.m3745m(drawable, "resource");
                MutabilityOwnership.m3745m(obj, "model");
                MutabilityOwnership.m3745m(iVar, "target");
                MutabilityOwnership.m3745m(aVar2, "dataSource");
                float intrinsicHeight = ((float) drawable.getIntrinsicHeight()) / ((float) drawable.getIntrinsicWidth());
                DetailImageViewHolder detailImageViewHolder = DetailImageViewHolder.this;
                int i = detailImageViewHolder.computeHeight(detailImageViewHolder.parentViewWidth, intrinsicHeight);
                DetailImageViewHolder.this.imageView.setLayoutParams(new FrameLayout.LayoutParams(-1, i));
                this.$imageItem.setHeight(i);
                DetailImageViewHolder.this.postCalcViewHeight(this.$imageItem);
                return false;
            }
        });
    }

    private final void bindTopImage(ImageItem imageItem) {
        int i;
        PixivIllust illust = imageItem.getIllust();
        float f = ((float) illust.height) / ((float) illust.width);
        if (illust.pageCount != 1) {
            i = computeHeight(this.parentViewWidth, f);
        } else if (f < MIN_HEIGHT_SCALE) {
            i = this.parentViewWidth;
        } else {
            i = computeHeight(this.parentViewWidth, f);
        }
        this.imageView.setLayoutParams(new FrameLayout.LayoutParams(-1, i));
        PixivImageLoader aVar = this.pixivImageLoader;
        Context context = this.itemView.getContext();
        MutabilityOwnership.m3746l(context, "itemView.context");
        aVar.m56j(context, illust.imageUrls.getLarge(), this.imageView);
        postCalcViewHeight(imageItem);
    }

    public final int computeHeight(int i, float f) {
        float f2 = (float) i;
        return (int) (f > MAX_HEIGHT_SCALE ? f2 * MAX_HEIGHT_SCALE : f2 * f);
    }

    public static final int getLayoutRes() {
        return Companion.getLayoutRes();
    }

    @Override // p270jp.pxv.android.viewholder.BaseViewHolder
    public void bind(Object obj) {
        MutabilityOwnership.m3745m(obj, "item");
        super.bind(obj);
        ImageItem imageItem = (ImageItem) obj;
        PixivIllust illust = imageItem.getIllust();
        int page = imageItem.getPage();
        if (page == 0) {
            bindTopImage(imageItem);
        } else {
            bindMultipleImage(imageItem);
        }
        this.imageView.setOnClickListener(new View.OnClickListener(this, page) { // from class: jp.pxv.android.viewholder.a

            /* renamed from: b */
            public final /* synthetic */ DetailImageViewHolder f19742b;

            /* renamed from: c */
            public final /* synthetic */ int f19743c;

            {
                this.f19742b = r2;
                this.f19743c = r3;
            }

            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                DetailImageViewHolder.m12305bind$lambda0(PixivIllust.this, this.f19742b, this.f19743c, view);
            }
        });
        this.imageView.setOnLongClickListener(new View.OnLongClickListener(page) { // from class: jp.pxv.android.viewholder.b

            /* renamed from: b */
            public final /* synthetic */ int f19745b;

            {
                this.f19745b = r2;
            }

            @Override // android.view.View.OnLongClickListener
            public final boolean onLongClick(View view) {
                return DetailImageViewHolder.m12306bind$lambda1(PixivIllust.this, this.f19745b, view);
            }
        });
    }
}
